package net.realsee.controller.wcs.device;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import net.realsee.common.annotation.Log;
import net.realsee.common.annotation.RepeatSubmit;
import net.realsee.common.enums.BusinessType;
import net.realsee.common.utils.poi.ExcelUtil;
import net.realsee.domain.wcs.device.bo.BindingEquipmentVehicleBo;
import net.realsee.domain.wcs.device.bo.BindingVehicleEquipmentBo;
import net.realsee.domain.wcs.device.bo.WcsVehicleEqptBo;
import net.realsee.domain.wcs.device.vo.EquipmentBindVehicleVo;
import net.realsee.domain.wcs.device.vo.VehicleBindEquipmentVo;
import net.realsee.domain.wcs.device.vo.WcsVehicleEqptVo;
import net.realsee.framework.core.controller.BaseController;
import net.realsee.framework.core.domain.PageQuery;
import net.realsee.framework.core.domain.R;
import net.realsee.framework.core.page.TableDataInfo;
import net.realsee.framework.core.validate.AddGroup;
import net.realsee.framework.core.validate.EditGroup;
import net.realsee.service.wcs.device.IWcsVehicleEqptService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 车辆设备关系
 *
 * @author realsee
 * @date 2023-08-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wcs/vehicleEqpt")
public class WcsVehicleEqptController extends BaseController {

    private final IWcsVehicleEqptService iWcsVehicleEqptService;

    /**
     * 查询车辆设备关系列表
     */
    @SaCheckPermission("wcs:vehicleEqpt:list")
    @GetMapping("/list")
    public TableDataInfo<WcsVehicleEqptVo> list(WcsVehicleEqptBo bo, PageQuery pageQuery) {
        return iWcsVehicleEqptService.selectVoPage(bo, pageQuery);
    }

    /**
     * 导出车辆设备关系列表
     */
    @SaCheckPermission("wcs:vehicleEqpt:export")
    @Log(title = "车辆设备关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WcsVehicleEqptBo bo, HttpServletResponse response) {
        List<WcsVehicleEqptVo> list = iWcsVehicleEqptService.selectVoList(bo);
        ExcelUtil.exportExcel(list, "车辆设备关系", WcsVehicleEqptVo.class, response);
    }

    /**
     * 获取车辆设备关系详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("wcs:vehicleEqpt:query")
    @GetMapping("/{id}")
    public R<WcsVehicleEqptVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long id) {
        return R.ok(iWcsVehicleEqptService.selectVoById(id));
    }

    /**
     * 新增车辆设备关系
     */
    @SaCheckPermission("wcs:vehicleEqpt:add")
    @Log(title = "车辆设备关系", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WcsVehicleEqptBo bo) {
        return toAjax(iWcsVehicleEqptService.insertByBo(bo));
    }

    /**
     * 修改车辆设备关系
     */
    @SaCheckPermission("wcs:vehicleEqpt:edit")
    @Log(title = "车辆设备关系", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WcsVehicleEqptBo bo) {
        return toAjax(iWcsVehicleEqptService.updateByBo(bo));
    }

    /**
     * 删除车辆设备关系
     *
     * @param ids 主键串
     */
    @SaCheckPermission("wcs:vehicleEqpt:remove")
    @Log(title = "车辆设备关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iWcsVehicleEqptService.deleteWithValidByIds(Arrays.asList(ids)));
    }

    /**
     * 获取设备信息
     *
     * @param id 主键
     */
    @GetMapping("/getEquipmentInfo/{id}")
    public R<EquipmentBindVehicleVo> getEquipment(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iWcsVehicleEqptService.getEquipmentInfo(id));
    }

    /**
     * 设备绑定车辆
     *
     * @param bo
     * @return
     */
    @Log(title = "设备绑定车辆", businessType = BusinessType.INSERT)
    @PutMapping("/insertEqptVehicle")
    public R<Void> insertEqptVehicle(@RequestBody BindingEquipmentVehicleBo bo) {
        iWcsVehicleEqptService.insertEqptVehicle(bo);
        return R.ok();
    }

    /**
     * 获取车辆信息
     *
     * @param id 主键
     */
    @GetMapping("/getVehicleInfo/{id}")
    public R<VehicleBindEquipmentVo> getVehicleInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iWcsVehicleEqptService.getVehicleInfo(id));
    }

    /**
     * 车辆绑定设备
     *
     * @param bo
     * @return
     */
    @Log(title = "车辆绑定设备", businessType = BusinessType.INSERT)
    @PutMapping("/insertVehicleEqpt")
    public R<Void> insertVehicleEqpt(@RequestBody BindingVehicleEquipmentBo bo) {
        iWcsVehicleEqptService.insertVehicleEqpt(bo);
        return R.ok();
    }
}
